﻿using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Telerik.Windows.Media.Imaging;

namespace Com.Lancetinc.Evs.Reports.RadPdf;

internal class ImageRenderer : UIElementRendererBase
{
    internal override bool Render(UIElement element, PdfRenderContext context)
    {
        var image = element as Image;
        if (image == null)
        {
            return false;
        }

        if (image.ActualWidth > 0 && image.ActualHeight > 0)
        {
            using var stream = new MemoryStream();
            ExportExtensions.ExportToImage(image, stream, new PngBitmapEncoder());
            context.drawingSurface.DrawImage(stream);
        }

        return true;
    }
}